import java.sql.*;

public class JDBCtest {
    public static void main(String[] args) throws Exception {
        //1.加载驱动
        Class.forName("com.mysql.cj.jdbc.Driver");
        //2.连接信息url,用户信息
        String url = "jdbc:mysql://localhost:3306/mysqlstudy?useUnicode=true&characterEncoding=utf8&useSSL=true&serverTimezone=UTC";
        String username = "root";
        String password = "Lzm924Lzm924";
        //3.连接,获得数据库对象connection
        Connection connection = DriverManager.getConnection(url, username, password);
        //4.获取执行sql的对象
        Statement statement = connection.createStatement();
        String sql = "select * from student2 where sid<10";
        //5.执行sql 查询操作
        ResultSet resultSet = statement.executeQuery(sql);
//        无返回值操作
//        statement.execute();
//        用于增删改
//        statement.executeUpdate();
        while (resultSet.next()) {
            System.out.println("sid:" + resultSet.getObject("sid") +
                    "sname:" + resultSet.getObject("sname"));
        }
        //6.释放连接
        resultSet.close();
        statement.close();
        connection.close();

    }
}
